package com.zhouyy.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zhouyy.api.dto.BuyByAppleAndStrawberryDTO;
import com.zhouyy.api.dto.FruitDTO;
import com.zhouyy.api.service.PracticeService;
import com.zhouyy.common.vo.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;


/**
 * <p> 练习控制器 </p>
 *
 * @author zhouyy
 * @description
 * @date 2024/03/25 18:18
 */
@RestController
@AllArgsConstructor
@RequestMapping("/practice")
@Api(tags = "练习")
public class PracticeController {

    @Resource
    private PracticeService practiceService;

    @ApiOperation("购买苹果和草莓")
    @PostMapping(value = "/buyAppleAndStrawberry")
    public ApiResult<BigDecimal> buyAppleAndStrawberry(@Validated @RequestBody BuyByAppleAndStrawberryDTO dto) {
        return ApiResult.ok(practiceService.getTotalPrice(BeanUtil.copyProperties(dto, FruitDTO.class)));
    }

    @ApiOperation("购买苹果、草莓和芒果")
    @PostMapping(value = "/buyAppleAndStrawberryAndMango")
    public ApiResult<BigDecimal> buyAppleAndStrawberryAndMango(@Validated @RequestBody FruitDTO dto) {
        return ApiResult.ok(practiceService.getTotalPrice(dto));
    }

    @ApiOperation("购买草莓打8折")
    @PostMapping(value = "/discountByStrawberry")
    public ApiResult<BigDecimal> buyAppleAndStrawberryAndMango2(@Validated @RequestBody FruitDTO dto) {
        return ApiResult.ok(practiceService.getTotalPriceByDiscount(dto));
    }

    @ApiOperation("满100减10")
    @PostMapping(value = "/fullReduction")
    public ApiResult<BigDecimal> getTotalPriceByFullReduction(@Validated @RequestBody FruitDTO dto) {
        return ApiResult.ok(practiceService.getTotalPriceByFullReduction(dto));
    }
}
